package com.example.service.impl;

import com.example.mapper.AccountYMapper;
import com.example.pojo.AccountY;
import com.example.service.IAccountYSerivce;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AccountYServiceImpl implements IAccountYSerivce
{
    @Resource
    private AccountYMapper accountYMapper;

//    登录
    @Override
    public Map<String, Object> loginY(AccountY accountY) {
        Map<String,Object> map=new HashMap<>();
        List<AccountY> list=accountYMapper.loginY(accountY);
        if(list.size()>=1){
            map.put("flag",true);
            map.put("message","登录成功！");
        }else {
            map.put("flag",false);
            map.put("message","登录失败！");
        }
        return map;
    }

//    查询运营账户
    @Override
    public Map<String, Object> getAccountY(AccountY accountY) {
        Map<String,Object> map=new HashMap<>();
        List<AccountY> list=accountYMapper.select(accountY);
        if (list.size()>=1){
            map.put("flag",true);
            map.put("message","数据查询成功！");
            map.put("rows",list);
            map.put("total",list.size());
        }else {
            map.put("flag",false);
            map.put("message","数据查询失败！");
            map.put("rows",list);
            map.put("total",list.size());
        }
        return map;
    }

//    添加
    @Override
    public Map<String, Object> addAccountY(AccountY accountY) {
        Map<String,Object> map=new HashMap<>();
        Integer count=accountYMapper.add(accountY);
        if (count>=1){
            map.put("flag",true);
            map.put("message","数据添加成功！");
            map.put("count",count);
        }else {
            map.put("flag",false);
            map.put("message","数据添加失败！");
            map.put("count",count);
        }
        return map;
    }

//    删除
    @Override
    public Map<String, Object> delAccountY(AccountY accountY) {
        Map<String,Object> map=new HashMap<>();
//        调用数据访问层的删除方法
        Integer count=accountYMapper.delete(accountY);
        if (count>=1){
            map.put("flag",true);
            map.put("message","数据删除成功！");
            map.put("count",count);
        }else {
            map.put("flag",false);
            map.put("message","数据删除失败！");
            map.put("count",count);
        }
        return map;
    }

//    更新
    @Override
    public Map<String, Object> modifyAccountY(AccountY accountY) {
        Map<String,Object> map=new HashMap<>();
        Integer count =accountYMapper.update(accountY);
        if(count>=1){
            map.put("flag",true);
            map.put("message","数据更新成功！");
            map.put("count",count);
        }else {
            map.put("flag",false);
            map.put("message","数据更新失败！");
            map.put("count",count);
        }
        return map;
    }
}
